home *** CD-ROM | disk | FTP | other *** search
- Path: li.net!jeremy
- From: jeremy@newshost.li.net (Jeremy Markman)
- Newsgroups: comp.lang.c,comp.unix.programmer
- Subject: Re: Q: '\n' character
- Followup-To: comp.lang.c,comp.unix.programmer
- Date: 3 Apr 1996 16:38:09 GMT
- Organization: LI Net (Long Island Network)
- Distribution: world
- Message-ID: <4ju9hh$o93@linet06.li.net>
- References: <31616F63.481D@lava.weeg.uiowa.edu>
- NNTP-Posting-Host: linet04.li.net
- X-Newsreader: TIN [version 1.2 PL2]
-
- Artur Wojdat (awojdat@lava.weeg.uiowa.edu) wrote:
- : Hello everybody,
- : Is there a function or some sort of way that I could remove '\n'
- : charecter form the end of the string. I'm reading from two files, want to
- : form one line of text and then have it printed out to stdout. I use fgets to
- : read from the file and I noticed that it appends newline char at the end.
-
- You could write an rtrim() function that will remove all whitespace (i.e.
- spaces, tabs, newline chars, etc) from the right side of your string.
-
- Here's an example of the function:
-
- #include <ctype.h>
-
- char *rtrim(char *string)
- {
- int i = strlen(string) - 1;
-
- if (i < 0) return(string);
-
- while (isspace(string[i]) && i >= 0)
- {
- string[i] = '\0';
- i--;
- }
-
- return(string);
- }
-